///////////////////////////////////////////////////////////////////////////////
//
// lighthouse3D - 3D Software Library
//
// File: CObjects.h
//
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2003-2013 Marcus Reinhardt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
///////////////////////////////////////////////////////////////////////////////
//
// You can find a copy of the GNU General Public License (gpl.txt) in the
// directory of the library.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef _CObjects_H_
#define _CObjects_H_

#include "math.h"

#include "CMathe3D.h"
#include "CMeshStorage.h"
#include "CFileHandler.h"
#include "CBasicClasses.h"

///////////////////////////////////////////////////////////////////////////////
// class CObjects : Contains implementations to create objects
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// 
//  Important notice for object creation
// 
//  [1]
//  The World Space Coord Sys looks the following way:
// 
//                       | y   / z
//                       |    /
//                       |   /
//                       |  /
//                       | /
//                       |/
//                       |------ x
// 
//  [2]
//  The light is calculated with the clock! So you have to place polygons
//  also with the clock!!! Example:
// 
// 
//                                 * P1
//                                /|
//                               / |
//                              /  |
//                             /   |
//                         P2 *----* P3
// 
// 
//  The correct order is P1->P3->P2 and NOT P1->P2->P3!!!
// 
///////////////////////////////////////////////////////////////////////////////


//! Height data for surfaces

struct THeightMap {

  int   xSize, zSize;
  float map[256][256];
  
};

//! Contains implementations to create objects

class CObjects {

  public:

    ///////////////////////////////////////////////////////////////////////////////
    // constructor/destructor
    ///////////////////////////////////////////////////////////////////////////////
    CObjects();
    ~CObjects();

    ///////////////////////////////////////////////////////////////////////////////
    // create different kind of objects
    ///////////////////////////////////////////////////////////////////////////////
    bool createPlane(CMeshStorage *s, const char *texname);
    bool createCube(CMeshStorage *s, const char *texname);
    bool createPyramid(CMeshStorage *s, const char *texname);
    bool createCylinder(CMeshStorage *s, const char *texname);
    bool createCone(CMeshStorage *s, const char *texname);
    bool createSphere(CMeshStorage *s, const char *texname);
    bool createSimpleSurface(CMeshStorage *s, const char *texname, const char *texname2,
                             const char *texname3, const char *texname4, const char *texname5);
    bool createHeightMapSurface(CMeshStorage *s, const char *hmname, const char *texname);
    
    ///////////////////////////////////////////////////////////////////////////////
    // other functions
    ///////////////////////////////////////////////////////////////////////////////
    void release();

    // Plane Attributes
    float planeSize;
    int planeSelect;

    // Cube Attributes
    float cubeSize;
    bool  cubeTopLess, cubeBottomLess;

    // Pyramid Attributes
    float pyramidSize;
    
    // Cylinder Attributes
    float cylinderHeight;
    float cylinderRadiusTop;
    float cylinderRadiusBottom;
    int   cylinderCirclePoints;

    // Cone Attributes
    float coneHeight;
    float coneRadiusBottom;
    int   coneCirclePoints;

    // Sphere Attributes
    float sphereVCircles;
    float spherePoints;
    float sphereRadius;

    // Simple Surface Attributes
    float simpleSurfaceBeachLevel;
    float simpleSurfaceDeepWaterLevel;
    float simpleSurfaceMultiplikator;
    float simpleSurfaceSeed;
    float simpleSurfaceSmoothLevel;
    float simpleSurfaceSnowLevel;
    float simpleSurfaceWaterLevel;
    float simpleSurfaceScaling;
    int   simpleSurfaceSizeX;
    int   simpleSurfaceSizeZ;

    // HeightMap Surface Attributes
	float heightMapSurfaceMultiplikator;
	float heightMapSurfaceMultiplikatorY;
	int   heightMapSurfaceAutoBalance;


  private:

    bool createHeightMap(THeightMap *h, int xSize, int ySize);
    bool normalizeHeightMap(THeightMap *h);
    bool scalingHeightMap(THeightMap *h, float scalingLevel);
    bool smoothHeightMap(THeightMap *h);
	TRGBColorTriple getRGBColor(unsigned int c);

    CFileHandler fileHandler;
    TMeshTexture t1;
	TPictureData p1, p2;

};

#endif
